package com.liyunc.demo.bundle.user.org.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author liyuncong
 * @version 1.0
 * @file UserBundleConfiguration.java
 * @brief UserBundleConfiguration
 * @details UserBundleConfiguration
 * @date 2022-04-01
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-04-01                  liyuncong          Created
 */
@Configuration
@MapperScan(basePackages = "com.liyunc.demo.bundle.user.org.dao.mapper")
public class UserBundleConfiguration {

    /**
     * 指定加密方式.
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        // 使用BCrypt加密密码
        return new BCryptPasswordEncoder();
    }

    /**
     * mybatis分页插件配置.
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        final PaginationInnerInterceptor interceptor = new PaginationInnerInterceptor();
        interceptor.setOverflow(true);
        interceptor.setDbType(DbType.POSTGRE_SQL);
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(interceptor);
        return mybatisPlusInterceptor;
    }
}
